home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / fp / ifp_unix.lzh / ifp / fproot / demo / FibSeq < prev    next >
Encoding:
Text File  |  1986-10-03  |  396 b   |  18 lines

  1. (*
  2.  * Fibonacci numbers
  3.  * 
  4.  * n : FibSeq -> sequence of first n Fibonacci numbers
  5.  *
  6.  * Example
  7.  *      6 : FibSeq -> <1 1 2 3 5 8>
  8.  *)
  9.  
  10. DEF FibSeq AS
  11.    IF [id,#2] | <= THEN
  12.       [#<1 1>,id] | takel       (* trivial case *)
  13.    ELSE
  14.       sub1 | FibSeq |           (* generate n-1 Fibonacci numbers        *)
  15.       [id, [1r,2r]|+] | apndr   (* append sum of last two to end of list *)
  16.    END;
  17.  
  18.